package com.zhanjixun.springcloud.demo.userprovider.controller;

import com.zhanjixun.springcloud.demo.userprovider.entities.SysUser;
import com.zhanjixun.springcloud.demo.userprovider.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author :zhanjixun
 * @date : 2019/8/25 13:04
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/user/add")
    public boolean add(@RequestBody SysUser sysUser) {
        if (StringUtils.isEmpty(sysUser.getNickname())) {
            sysUser.setNickname("用户" + sysUser.getAccount());
        }
        return userService.addUser(sysUser);
    }

    @PostMapping("/user/login")
    public SysUser login(@RequestBody SysUser sysUser) {
        return userService.queryUser(sysUser.getAccount(), sysUser.getPassword());
    }

    @GetMapping("/user/get/{account}")
    public SysUser add(@PathVariable("account") String account) {
        return userService.queryUser(account);
    }

}
